<div class="layui-container fly-marginTop fly-user-main">
  {include file="common/menu"}

  <div class="site-tree-mobile layui-hide">
    <i class="layui-icon">&#xe602;</i>
  </div>
  <div class="site-mobile-shade"></div>

  <div class="site-tree-mobile layui-hide">
    <i class="layui-icon">&#xe602;</i>
  </div>
  <div class="site-mobile-shade"></div>


  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title" id="LAY_mine">
        <li data-type="mine-jie" lay-id="index" class="layui-this">全部帖子（<span>{$countAll}</span>）</li>
        <li data-type="collection" data-url="/collection/find/" lay-id="collection">未结帖子（<span>{$countOpen}</span>）</li>
        <li data-type="collection" data-url="/collection/find/" lay-id="collection">已结帖子（<span>{$countClose}</span>）
        </li>
      </ul>


      <div class="layui-tab-content" style="padding: 20px 0;">

        <!-- 全部 -->
        <div class="layui-tab-item layui-show">
          <ul class="mine-view jie-row">
            {foreach $postAll as $item}
            <li>
              <h2 style="display: block;padding: 8px 0;">
                <a class="layui-badge"
                  style="background: none; color: #009688;border: 1px solid #009688;width: 100px;">{$item['cate']['name']}</a>
                <span style="background: none; color: #333;font-size: 20px;">标题：</span>
                <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $item['cateid']])}"
                  style="font-size: 20px;">{$item['title']}</a>

                {if condition="$item['state'] != '0'"}
                <span class="layui-badge layui-bg-red">{$item.state_text}</span>
                {/if}

                {if condition="$item['accept']"}
                <span class="layui-badge fly-badge-accept layui-hide-xs" style="color: #fff;background: #999;">已结</span>
                {/if}

              </h2>
              <div class="fly-list-info" style="width: 100%;">
                <span style="color: #999;background: none;">{$item['createtime']}</span>
                <span class="fly-list-kiss layui-hide-xs" title="悬赏飞吻" style="color: #999;background: none;"><i
                    class="iconfont icon-kiss"></i>
                  {$item['visit_text']}</span>

                <span class="fly-list-nums" style="color: #999;background: none;">
                  <i class="iconfont icon-pinglun1" title="回答"></i> {$item['comment']}
                </span>
                {if condition="$item.user.id == $Think.cookie.LoginUser['id']"}
                <span onclick="delOne(`{$item['id']}`)" class="layui-btn layui-btn-xs jie-admin"
                  style="background: red;float: right;" type="del" id="del">删除</span>
                {/if}

                {if condition="$item.user.id == $Think.cookie.LoginUser['id']"}
                <span class="layui-btn layui-btn-xs jie-admin" type="edit" style="background: plum;float: right;"><a
                    href="{:url('home/post/edit', ['postid' => $item.id])}">编辑此贴</a></span>
                {/if}
              </div>

            </li>
            {/foreach}
          </ul>
          <div id="LAY_page">
            {$pageOpenstr}
          </div>
        </div>

        <!-- 未结 -->
        <div class="layui-tab-item">
          <ul class="mine-view jie-row">
            {foreach $postOpen as $item}
            <li>
              <h2 style="display: block;padding: 8px 0;">
                <a class="layui-badge"
                  style="background: none; color: #009688;border: 1px solid #009688;width: 100px;">{$item['cate']['name']}</a>
                <span style="background: none; color: #333;font-size: 20px;">标题：</span>
                <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $item['cateid']])}"
                  style="font-size: 20px;">{$item['title']}</a>

                {if condition="$item['state'] != '0'"}
                <span class="layui-badge layui-bg-red">{$item.state_text}</span>
                {/if}

                {if condition="$item['accept']"}
                <span class="layui-badge fly-badge-accept layui-hide-xs" style="color: #fff;background: #999;">已结</span>
                {/if}

              </h2>
              <div class="fly-list-info" style="width: 100%;">
                <span style="color: #999;background: none;">{$item['createtime']}</span>
                <span class="fly-list-kiss layui-hide-xs" title="悬赏飞吻" style="color: #999;background: none;"><i
                    class="iconfont icon-kiss"></i>
                  {$item['visit_text']}</span>

                <span class="fly-list-nums" style="color: #999;background: none;">
                  <i class="iconfont icon-pinglun1" title="回答"></i> {$item['comment']}
                </span>
                {if condition="$item.user.id == $Think.cookie.LoginUser['id']"}
                <span onclick="delOne(`{$item['id']}`)" class="layui-btn layui-btn-xs jie-admin"
                  style="background: red;float: right;" type="del" id="del">删除</span>
                {/if}

                {if condition="$item.user.id == $Think.cookie.LoginUser['id']"}
                <span class="layui-btn layui-btn-xs jie-admin" type="edit" style="background: plum;float: right;"><a
                    href="{:url('home/post/edit', ['postid' => $item.id])}">编辑此贴</a></span>
                {/if}
              </div>

            </li>
            {/foreach}
          </ul>
          <div id="LAY_page1">
            {$pageOpenstr}
          </div>
        </div>

        <!-- 已结 -->
        <div class="layui-tab-item">
          <ul class="mine-view jie-row">
            {foreach $postClose as $item}
            <li>
              <h2 style="display: block;padding: 8px 0;">
                <a class="layui-badge"
                  style="background: none; color: #009688;border: 1px solid #009688;width: 100px;">{$item['cate']['name']}</a>
                <span style="background: none; color: #333;font-size: 20px;">标题：</span>
                <a href="{:url('home/index/info', ['postid' => $item.id,'cateid' => $item['cateid']])}"
                  style="font-size: 20px;">{$item['title']}</a>

                {if condition="$item['state'] != '0'"}
                <span class="layui-badge layui-bg-red">{$item.state_text}</span>
                {/if}

                {if condition="$item['accept']"}
                <span class="layui-badge fly-badge-accept layui-hide-xs" style="color: #fff;background: #999;">已结</span>
                {/if}

              </h2>
              <div class="fly-list-info" style="width: 100%;">
                <span style="color: #999;background: none;">{$item['createtime']}</span>
                <span class="fly-list-kiss layui-hide-xs" title="悬赏飞吻" style="color: #999;background: none;"><i
                    class="iconfont icon-kiss"></i>
                  {$item['visit_text']}</span>

                <span class="fly-list-nums" style="color: #999;background: none;">
                  <i class="iconfont icon-pinglun1" title="回答"></i> {$item['comment']}
                </span>

                {if condition="$item.user.id == $Think.cookie.LoginUser['id']"}
                <span onclick="delOne(`{$item['id']}`)" class="layui-btn layui-btn-xs jie-admin"
                  style="background: red;float: right;" type="del" id="del">删除</span>
                {/if}

                {if condition="$item.user.id == $Think.cookie.LoginUser['id']"}
                <span class="layui-btn layui-btn-xs jie-admin" type="edit" style="background: plum;float: right;"><a
                    href="{:url('home/post/edit', ['postid' => $item.id])}">编辑此贴</a></span>
                {/if}

              </div>

            </li>
            {/foreach}
          </ul>
          <div id="LAY_page2">
            {$pageClosestr}
          </div>
        </div>


      </div>
    </div>


  </div>


</div>

<script>
  function delOne(id) {
    var postId = id;

    layui.use('layer', function () {
      var layer = layui.layer
      var $ = layui.jquery


      layer.confirm('是否确认删除', {
        icon: 3,
        title: '提示'
      }, function (index) {
        $.ajax({
          type: 'POST',
          url: `{:url('home/post/delete')}`,
          data: {
            postid: postId,
          },
          success: function (data) {

            if (data.result) {
              layer.msg(data.msg, {
                icon: 1,
                time: 2000 // 2秒关闭(如果不配，默认是3秒)
              }, function () {
                location.href = "{:url('home/user/post')}"
                return false;
              })
            } else {
              // 删除失败
              layer.msg(data.msg)
            }
          }
        })
      })
    })

  }


</script>